//
//  SISSEvaluateHouseViewController.m
//  SISSAPP
//
//  Created by 优房网 on 2017/5/3.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSEvaluateHouseViewController.h"
#import "SISSPickerView.h"

@interface SISSEvaluateHouseViewController ()

@property (weak, nonatomic) IBOutlet UITextField *ownerClassTextField;
@property (weak, nonatomic) IBOutlet UILabel *secondTitleLabel;
@property (weak, nonatomic) IBOutlet UITextField *IDCardTextField;
@property (weak, nonatomic) IBOutlet UITextField *certificateClassTextField;
@property (weak, nonatomic) IBOutlet UITextField *certificateNoTextField;

/* ownerIndex */
@property (assign, nonatomic) NSInteger ownerIndex;
/* certificateIndex */
@property (assign, nonatomic) NSInteger certificateIndex;

@end

@implementation SISSEvaluateHouseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.ownerIndex = 0;
    self.certificateIndex = 0;
}
/**
 选择权利人类别点击事件
 */
- (IBAction)chooseOwnerClassClickAction:(id)sender {
    
    [self.view endEditing:YES];
    
    SISSPickerView *pickerView = [[SISSPickerView alloc] initWithFrame:self.view.bounds];
    pickerView.title = @"权利人类别";
    pickerView.titleArray = @[@"个人", @"单位"];
    pickerView.isArea = NO;
    pickerView.firstIndex = self.ownerIndex;
    __weak typeof(self) weakself = self;
    pickerView.completion = ^(NSString *firstTitle, NSString *secondTitle, NSInteger firstIndex, NSInteger secondIndex) {
        
        weakself.ownerClassTextField.text = [NSString stringWithFormat:@"%@",firstTitle];
        weakself.ownerIndex = firstIndex;
        weakself.secondTitleLabel.text = firstIndex == 1 ? @"单位名称" : @"身份证号码";
        weakself.IDCardTextField.placeholder = firstIndex == 1 ? @"请输入单位名称" : @"请输入身份证号码";
    };
}


/**
 选择证书类别点击事件
 */
- (IBAction)chooseCertificateClassClickAction:(id)sender {
    
    [self.view endEditing:YES];
    
    SISSPickerView *pickerView = [[SISSPickerView alloc] initWithFrame:self.view.bounds];
    pickerView.title = @"证书类别";
    pickerView.titleArray = @[@"房地产权证书", @"不动产权证书"];
    pickerView.isArea = NO;
    pickerView.firstIndex = self.certificateIndex;
    __weak typeof(self) weakself = self;
    pickerView.completion = ^(NSString *firstTitle, NSString *secondTitle, NSInteger firstIndex, NSInteger secondIndex) {
        
        weakself.certificateClassTextField.text = [NSString stringWithFormat:@"%@",firstTitle];
        weakself.certificateIndex = firstIndex;
        
    };
}

#pragma mark - 查询按钮点击事件
- (IBAction)queryButtonClickAction:(id)sender {
    
    if (self.ownerClassTextField.text.length == 0) {
        [SISSTools showSVErrorTitle:@"请选择权利人类别" andTime:2 andColor:YES];
        return;
    }
    if (self.IDCardTextField.text.length == 0) {
        [SISSTools showSVErrorTitle:@"请输入身份证号码" andTime:2 andColor:YES];
        return;
    }
    if (![NSString checkUserIdCard:self.IDCardTextField.text]) {
        [SISSTools showSVErrorTitle:@"请输入正确的身份证号码" andTime:2 andColor:YES];
        return;
    }
    if (self.certificateClassTextField.text.length == 0) {
        [SISSTools showSVErrorTitle:@"请选择证书类别" andTime:2 andColor:YES];
        return;
    }
    if (self.certificateNoTextField.text.length == 0) {
        [SISSTools showSVErrorTitle:@"请输入证书编号" andTime:2 andColor:YES];
        return;
    }
    
    
}


@end
